//
//  DLBaseTabBarViewController.m
//  DGGUIKit
//
//  Created by dgg_hzk on 2019/11/21.
//

#import "DLBaseTabBarViewController.h"
#import "DLBaseNavigationController.h"
#import <ReactiveObjC/ReactiveObjC.h>

@interface DLBaseTabBarViewController ()

@end

@implementation DLBaseTabBarViewController


+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    
    DLBaseTabBarViewController *viewController = [super allocWithZone:zone];
    
    @weakify(viewController)
    
    [[viewController rac_signalForSelector:@selector(viewDidLoad)] subscribeNext:^(id x) {
        
        @strongify(viewController)
        [viewController dgg_addSubviews];
        [viewController dgg_addNavItems];
        [viewController dgg_requestData];
        
        
        
    }];
    
    
    [[viewController rac_signalForSelector:@selector(viewWillAppear:)] subscribeNext:^(id x) {
        
        @strongify(viewController)
        [viewController dgg_layoutNavigation];
        [viewController dgg_requestNewData];
    }];
    
    [[viewController rac_signalForSelector:@selector(viewWillDisappear:)] subscribeNext:^(id x) {
        
        @strongify(viewController)
        [viewController dgg_recoverKeyboard];
        
    }];
    

    
    return viewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13 ], NSFontAttributeName, nil] forState:UIControlStateNormal];
    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13  ], NSFontAttributeName,nil] forState:UIControlStateSelected];
    [self.tabBar setTintColor:[UIColor colorWithHex:0x1D90F5]];
    [self dgg_setNav];
    
}
- (void)dgg_setNav
{
    if (self.navigationController) {
        if ([self.navigationController isKindOfClass:[DLBaseNavigationController class]]) {
//            DLBaseNavigationController *nav = (DLBaseNavigationController*)self.navigationController;
//            [nav setNavWithViewController:self];
        }
    }
}
/**
 添加UI 设置UI
 */
- (void)dgg_addSubviews{}

/**
 设置导航 本方法每次在viewWillAppear会调用
 */
- (void)dgg_layoutNavigation{}

/**
 数据请求 本方法每次在viewWillAppear会调用
 */
- (void)dgg_requestNewData{}

/**
 数据请求 本方法在viewDidLoad会调用
 */
- (void)dgg_requestData{}
/**
 添加导航item
 */
- (void)dgg_addNavItems{}
/**
 隐藏键盘
 */
- (void)dgg_recoverKeyboard
{
    [self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc {
    
    NSLog(@"♦️释放♦️ %@ '%@'", NSStringFromSelector(_cmd), self.class);
}

#pragma mark - 屏幕方向切换
//是否可以旋转
- (BOOL)shouldAutorotate
{
    return self.selectedViewController.shouldAutorotate;
}
//支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return self.selectedViewController.supportedInterfaceOrientations;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
